<?php
/**
 * Created by PhpStorm.
 * User: lzy
 * Date: 2019/6/12
 * Time: 15:51
 */

namespace App\Http\Controllers\Admin\View;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Eloquent\User;
use App\Http\Repositories\Services\IRole;
use App\Http\Repositories\Services\IUser;
use Illuminate\Http\Request;

class UserController extends Controller
{
    protected $userService;
    protected $roleService;

    public function __construct(
        IUser $userService,
        IRole $roleService
    )
    {
        $this->userService = $userService;
        $this->roleService = $roleService;
    }

    public function index(){
        return view('admin.user.index');
    }

    public function update($id){
        $dao = $this->userService->byId($id);
        return view('admin.user.edit',['dao'=>$dao]);
    }

    public function store(){
        return view('admin.user.create');
    }

    /**
     * 设置权限
     *
     * @param $id
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function role($id){
        $user = $this->userService->byId($id);
        $roles = $user->getRoleNames();
        if ($roles) {
            $roles = $roles->toArray();
        }else{
            $roles = [];
        }
        $dao = $this->roleService->getAll();
        return view('admin.user.role',['dao'=>$dao,'id'=>$id,'roles'=>$roles]);
    }
}